package com.karson.front.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.karson.common.model.Author;
import com.karson.common.model.CirclesInfo;
import com.karson.common.response.CommonResult;
import com.karson.service.service.CirclesInfoService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author ZKS
 */
@RestController
@RequestMapping("/api/circle")
@Tag(name = "社团接口")
public class CircleController {
    @Autowired
    private CirclesInfoService circlesInfoService;
    @Operation(summary = "全部列表（按workCount排序，前端使用虚拟化技术）")
    @GetMapping("/list")
    public CommonResult<List<CirclesInfo>> getList(
            @RequestParam(value = "sortDesc", required = false, defaultValue = "true") boolean sortDesc
    ) {
        LambdaQueryWrapper<CirclesInfo> queryWrapper = Wrappers.lambdaQuery();
        if (sortDesc) {
            queryWrapper.orderByDesc(CirclesInfo::getWorkCount);
        } else {
            queryWrapper.orderByAsc(CirclesInfo::getWorkCount);
        }

        List<CirclesInfo> list = circlesInfoService.list(queryWrapper);
        return CommonResult.success(list);
    }
}
